<?php

class Category extends AdminController {

    public function __construct() {
        parent::__construct();
    }
    
    public function index() 
    {   
        $this->view->list = $this->model->get();
        $this->view->render('category/index');
    }
    
    public function add()
    {
        $this->view->render('category/add');
    }
    
    public function create()
    {
        $this->model->create();
        header('location: ' . URL . 'category');
    }
    
    public function view( $id = null)
    {
        if ( $id == null)
            header('location: ' . URL . 'error');
        
        $table = $this->model->find( $id);
        $this->view->table = $table;
        $this->view->list = $this->model->getSchema( $table['name']);
        $this->view->render('category/view');
    }
    
    public function delete( $id = null)
    {
        if ( $id == null)
            header('location: ' . URL . 'error');
        
        $this->model->delete( $id);
        header('location: ' . URL . 'category');
    }
    
    public function edit( $id = null)
    {
        if ( $id == null)
            header('location: ' . URL . 'error');
        
        $this->view->render('category/edit');
    }
}